package com.example.demo.dto;

import lombok.Data;

@Data
public class ResponseDTO<T> {

    private int errCode;
    private String errMsg;
    private T data;

    public ResponseDTO() {

    }
    public ResponseDTO(int errCode) {
        this.errCode = errCode;
    }


    public static <T> ResponseDTO<T> ok(T data) {
        ResponseDTO<T> dto = new ResponseDTO<>(0);
        dto.setData(data);
        return dto;
    }

    public static <T> ResponseDTO<T> ok() {
        return ok(null);
    }


    public static <T> ResponseDTO<T> error() {
        return error(-1,"");
    }

    public static <T> ResponseDTO<T> error(String errMsg) {
        return error(-1,errMsg);
    }

    public static <T> ResponseDTO<T> error(int errCode,String errMsg) {
        ResponseDTO<T> dto = new ResponseDTO<>(errCode);
        dto.setErrMsg(errMsg);
        return dto;
    }

}
